package top.songxs.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import top.songxs.base.BaseController;
import top.songxs.entity.Dict;
import top.songxs.result.Result;
import top.songxs.service.DictService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {
    @Reference
    private DictService dictService;
    @RequestMapping
    public String index(){
        return "dict/index";
    }
    //返回值不是znodes，而是Result.ok(znodes)
    @GetMapping(value = "/findZnodes")
    @ResponseBody
    public Result findByParentId(@RequestParam(value = "id", defaultValue = "0") Long parentId){
        List<Map<String, Object>> znodes = dictService.findZnodes(parentId);
        return Result.ok(znodes);
    }
    /**
     * 根据上级id获取子节点数据列表
     * @param parentId
     * @return
     */
    @GetMapping(value = "findListByParentId/{parentId}")
    @ResponseBody
    public Result<List<Dict>> findListByParentId(@PathVariable Long parentId) {
        List<Dict> list = dictService.findListByParentId(parentId);
        return Result.ok(list);
    }
    /**
     * 根据编码获取子节点数据列表
     * @param dictCode
     * @return
     */
    @GetMapping(value = "findListByDictCode/{dictCode}")
    @ResponseBody
    public Result<List<Dict>> findListByDictCode(@PathVariable String dictCode) {
        List<Dict> list = dictService.findListByDictCode(dictCode);
        return Result.ok(list);
    }
}
